package com.jinly.ryder.manage.service.model;


import com.jinly.ryder.common.service.model.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.text.MessageFormat;

@Getter
@AllArgsConstructor
public enum DatabaseType implements BaseEnum {
    MYSQL("mysql", "com.mysql.cj.jdbc.Driver",
            "jdbc:mysql://{0}:{1}/{2}?autoReconnect=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8&&characterEncoding=utf-8"),
    H2_LOCAL("h2 local", "org.h2.Driver",
            "jdbc:h2:~/{2};MODE=MYSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;");


    private String name;
    private String driverClass;
    private String urlTemplate;

    public String getUrl(String host, Integer port, String databaseName) {
        return MessageFormat.format(urlTemplate, host, String.valueOf(port), databaseName);
    }
}

